package dao;

import java.sql.*;

import model.*;

public class AdminDao {
private static AdminDao adminDao=new AdminDao();
private AdminDao() {};
/*
  饿汉单例模式，
  保证系统中只有一个实例
  可节约内存、提升效率等
 */
public static AdminDao getInstance() {
	return adminDao; 
}
public Admin queryAdmin(int id,String password) {
	String sql="select * from Admin where id="+id+" and password="+password+"";
	Admin admin=null;
	Connection conn=BaseConn.getConn();;
	PreparedStatement pstm=null;
	ResultSet res=null;
try {
    pstm=conn.prepareStatement(sql);
	res=pstm.executeQuery();
	while(res.next()) {
		int returnId=res.getInt("id");
		String returnPswd=res.getString("password");
		admin=new Admin(returnId,returnPswd);
		}
}catch(SQLException e) {
	e.printStackTrace();
}finally {
	
	try {
		res.close();
		pstm.close();
		conn.close();
	} catch (SQLException e) {
		
		e.printStackTrace();
	}
	
	}
	
		return admin;
	}

}

